home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 April / PCWorld_2007-04_cd.bin / audio-video / kmplayer / kmp.exe / Shader / EdgeSharpen v1_1.txt < prev    next >
Text File  |  2006-09-08  |  2KB  |  69 lines

  1. // EdgeSharpen v1.1=ps_2_0
  2. // http://www.homecinema-fr.com/forum/viewtopic.php?t=29814317 
  3.  
  4. sampler s0 : register(s0); 
  5. float4 p0 : register(c0); 
  6. float4 p1 : register(c1); 
  7.  
  8. #define width (p0[0]) 
  9. #define height (p0[1]) 
  10. #define counter (p0[2]) 
  11. #define clock (p0[3]) 
  12. #define one_over_width (p1[0]) 
  13. #define one_over_height (p1[1]) 
  14.  
  15. #define PI acos(-1) 
  16.  
  17. #define Edge_width      2.0 
  18. #define Edge_threshold       0.2 
  19.  
  20. #define Sharpen_width       1.2 
  21. #define Sharpen_val0       2.0 
  22. #define Sharpen_val1       0.125 
  23.  
  24. float4 main(float2 tex : TEXCOORD0) : COLOR 
  25.    // Read current pixel color 
  26.    float4 Res = tex2D( s0, tex ); 
  27.  
  28.    // Edge detection width vector 
  29.    float dx = Edge_width / height; 
  30.    float dy = Edge_width / width; 
  31.  
  32.    // Read corners color 
  33.    float4 c2 = tex2D(s0, tex + float2( 0,-dy) ); 
  34.    float4 c3 = tex2D(s0, tex + float2(-dx,0) ); 
  35.    float4 c4 = tex2D(s0, tex + float2( dx,0) ); 
  36.    float4 c5 = tex2D(s0, tex + float2( 0, dy) ); 
  37.  
  38.    // Compute vector lenght 
  39.    float4 c0 = Res*4 - c2 - c3 - c4 - c5; 
  40.  
  41.    // If vector lenght > Edge_threshold : sharp this pixel 
  42.    if( length(c0) > Edge_threshold ) 
  43.    { 
  44.       // Compute sharpen's width vector 
  45.       dx = Sharpen_width / width; 
  46.       dy = Sharpen_width / height; 
  47.   
  48.       // Read 8 around pixels color 
  49.       float4 c1 = tex2D(s0, tex + float2(-dx,-dy)) ; 
  50.       c2 = tex2D(s0, tex + float2(0,-dy)) ; 
  51.       c3 = tex2D(s0, tex + float2(-dx,0)) ; 
  52.       c4 = tex2D(s0, tex + float2(dx,0)); 
  53.       c5 = tex2D(s0, tex + float2(0,dy)) ; 
  54.       float4 c6 = tex2D(s0, tex + float2(dx,dy)) ; 
  55.       float4 c7 = tex2D(s0, tex + float2(-dx,+dy)); 
  56.       float4 c8 = tex2D(s0, tex + float2(+dx,-dy)) ; 
  57.  
  58.       float4 c9 =Res * Sharpen_val0; 
  59.  
  60.       Res = c9 - (c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 ) * Sharpen_val1 ; 
  61.  
  62.       // Uncomment next line to see detected Edges in red ... 
  63.       //Res = float4( 1.0, 0.0, 0.0, 0.0 ); 
  64.  
  65.    } 
  66.  
  67.    return Res; 
  68. }